# coding: utf-8
import sys, os

sys.path.append(os.pardir)  # 为了导入父目录中的文件而进行的设定
import numpy as np
from common.functions import softmax, cross_entropy_error
from common.gradient import numerical_gradient


class simpleNet:
    def __init__(self):
        self.W = np.random.randn(2, 3)

    def predict(self, x):
        return np.dot(x, self.W)

    def loss(self, x, t):
        z = self.predict(x)
        y = softmax(z)
        loss = cross_entropy_error(y, t)

        return loss


x = np.array([0.6, 0.9])
t = np.array([0, 0, 1])

net = simpleNet()
# net.W[0][0] = 1.0508660056480195
# net.W[0][1] = 0.4211756825692872
# net.W[0][2] = -0.25813081602958354
# net.W[1][0] = 1.5104672585652146
# net.W[1][1] = 1.473981953406675
# net.W[1][2] = 0.5655542831645135

net.W[0][0] = 1.05
net.W[0][1] = 0.42
net.W[0][2] = -0.25
net.W[1][0] = 1.51
net.W[1][1] = 1.47
net.W[1][2] = 0.56

f = lambda w: net.loss(x, t)
dW = numerical_gradient(f, net.W)

print(dW)


